package cz.cvut.fit.mi_paa;

import cz.cvut.fit.mi_paa.abs.Context;
import cz.cvut.fit.mi_paa.abs.Strategy;
import cz.cvut.fit.mi_paa.abs.StrategyFactory;
import cz.cvut.fit.mi_paa.bucket.*;
import cz.cvut.fit.mi_paa.abs.SolutionTypeEnum;
import cz.cvut.fit.mi_paa.knapsack.KnapsackContext;
import cz.cvut.fit.mi_paa.sat.SatContext;
import cz.cvut.fit.mi_paa.utils.StopWatch;

import java.io.*;
import java.util.*;

/**
 * Created with IntelliJ IDEA.
 * User: milos
 * Date: 28.9.12
 * Time: 0:08
 * To change this template use File | Settings | File Templates.
 */

public class Main {

    public static void main(String[] args) throws IOException, CloneNotSupportedException {
        final SolutionTypeEnum TYPE = SolutionTypeEnum.SAT_ANNEALING;
//        File directory = new File("/home/milos/Stažené/instance/");
        File directory = new File("/home/milos/Projekty/FIT/MI-PAA/semestralka/data/task6/");

        for(File f : directory.listFiles()) {
            if(!f.getName().endsWith(".wcnf")) continue;
            Map<String,String[]> params = new HashMap<String,String[]>();
//            String changingParameter = "costCoef";
//            nejlepsi hodnoty
            String initTempType="1";
            String costCalcType="5";
//
//            String[] costCalcTypes = {"1","2","3","4","5","6"};
//            String[] initTempTypes = {"1","2","3","4","5"};
//            for (String costCalcType : costCalcTypes) {
//                for(String initTempType : initTempTypes) {
//                    File outputFile = new File(f.getPath() + ".sol."+TYPE.getName()+"."+costCalcType+".initTemp"+initTempType);
//            File outputFile = new File(f.getPath() + ".sol."+TYPE.getName()+"."+changingParameter);
            File outputFile = new File(f.getPath() + ".sol."+TYPE.getName());
            FileReader inputReader = new FileReader(f);
            BufferedReader inputBufferedReader = new BufferedReader(inputReader);
            FileWriter resultWriter = new FileWriter(outputFile);
            StopWatch sw = new StopWatch();

            Context context = new SatContext(resultWriter,inputBufferedReader,sw);
            StrategyFactory factory = new StrategyFactory(context);
            context.nextInstance();
            String[] array1 = {"0.1","0.05","0.01","0.005","0.001","0.0005","0.0001"};
            params.put("frozenCoef",array1);
            String[] array2 = {"0.2","0.4","0.6","0.8","0.85","0.88","0.9","0.95","0.99"};
            params.put("coolingCoef",array2);
            String[] array3 = {"0.1","0.5","0.9","1","5","10","15","20","25","30"};
            params.put("initTempCoef",array3);
            String[] array4 = {"1","3","5","7","9","13","15","17","20"};
            params.put("iterationThresholdCoef",array4);
            String[] array5 = {"1","5","10","30","50","70","100","150","200","250","300","400","500","600","700","800","900","1000"};
            params.put("costCoef",array5);
//            int iterationCount=5;
//            for (int i=0;i<iterationCount;i++){
//            for (String s : params.get(changingParameter)) {
                String[] strategyArgs = {"0.05","0.85","30","15","100",initTempType,costCalcType};
                Strategy strategy = factory.getStrategy(TYPE);
                strategy.setArgs(strategyArgs);
                strategy.solve();
                strategy.writeResult();
//            }
//            }
            context.close();

//            }
//            }
        }
    }

//    public static void main(String[] args) throws IOException, CloneNotSupportedException {
//        final SolutionTypeEnum TYPE = SolutionTypeEnum.KNAP_ANNEALING;
//        String fileName = "/home/milos/Projekty/FIT/MI-PAA/semestralka/data/task5/instance.dat";
//        File inputFile = new File(fileName);
//        File outputFile = new File(fileName + ".sol."+TYPE.getName()+".frozen");
//        FileReader inputReader = new FileReader(inputFile);
//        BufferedReader inputBufferedReader = new BufferedReader(inputReader);
//        FileWriter resultWriter = new FileWriter(outputFile);
//        StopWatch sw = new StopWatch();
//
//        Context context = new KnapsackContext(resultWriter,inputBufferedReader,sw);
//        StrategyFactory factory = new StrategyFactory(context);
////        pocatecni teplota
////        String[] dynamicParam = {"0.1","0.3","0.5","0.7","0.9","1","1.2","1.4"};
////        vnitrni smycka
////        String[] dynamicParam = {"0.5","1","1.5","2","2.5","3","3.5","4","4.5","5","5.5","6","6.5","7","7.5","8"};
////        koef ochlazovani
////        String[] dynamicParam = {"0.2","0.4","0.6","0.8","0.85","0.88","0.9","0.95","0.99"};
////        frozen
//        String[] dynamicParam = {"0.1","0.2","0.3","0.4","0.5","0.6","0.7","0.8","0.9","1"};
////      [finalTemp=0.1,temperatureCoeficient=0.9,initialTemperature=0.9,innerCycleIterationsMaxCount=2]
//        while(context.nextInstance()) {
//            for (String param : dynamicParam){
//                //optimalni parametry
//                //String[] strategyArgs = {"2","0.9","0.7","3"};
//                String[] strategyArgs = {param,"0.9","0.9","2"};
//                Strategy strategy = factory.getStrategy(TYPE);
//                strategy.setArgs(strategyArgs);
//                strategy.solve();
//                strategy.writeResult();
//            }
//        }
//
//        context.close();
//    }



//    public static void main(String[] args) throws IOException, CloneNotSupportedException {
//        final SolutionTypeEnum TYPE = SolutionTypeEnum.KNAP_PRICEWEIGHT;
//        String[] fileNames = {"C50","C150","C250","C350","C450","d00","d10","d-10","m02","m04","m06","m08","m10","W100","W150","W200","W250","W300"};
//        for (String name : fileNames) {
//            String fileName = "/home/milos/Projekty/FIT/MI-PAA/semestralka/data/task4/"+ name;
//            File inputFile = new File(fileName);
//            File outputFile = new File(fileName + ".sol."+TYPE.getName());
//            FileReader inputReader = new FileReader(inputFile);
//            BufferedReader inputBufferedReader = new BufferedReader(inputReader);
//            FileWriter resultWriter = new FileWriter(outputFile);
//            StopWatch sw = new StopWatch();
//
//            Context context = new KnapsackContext(resultWriter,inputBufferedReader,sw);
//            StrategyFactory factory = new StrategyFactory(context);
//            while (context.nextInstance()) {
//                Strategy strategy = factory.getStrategy(TYPE);
//                strategy.solve();
//                strategy.writeResult();
//            }
//            context.close();
//        }
//    }
}
